package net.grzechocinski.wordcounter.comparators;

import net.grzechocinski.wordcounter.KMP.WordObject;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Mateusz
 * @since 2010-05-08
 */
public enum SortOrder {

	ALONE(1){
		@Override
		public Comparator<WordObject> getComparator() {
			return new AloneComparator();
		}},

	IN_OTHER(2){
		@Override
		public Comparator<WordObject> getComparator() {
			return new InOtherComparator();
		}};

	private int sortableColumnIndex;

	SortOrder(int sortableColumnIndex) {
		this.sortableColumnIndex = sortableColumnIndex;
	}

	public static SortOrder valueOf(int sortableColumnIndex){
		for(SortOrder sortOrder : values()){
			if(sortOrder.sortableColumnIndex == sortableColumnIndex){
				return sortOrder;
			}
		}
		throw new IllegalArgumentException("Could not find sorting mode " + sortableColumnIndex + ". Available modes: " + Arrays.deepToString(values()));
	}

	@Override
	public String toString() {
		return name() + "->" + sortableColumnIndex;
	}

	public abstract Comparator<WordObject> getComparator();
}
